package work2;

import Uti.ScannerUti;

public class Grade implements Comparable<Grade> {
    String name;
    double javaScore;
    double sqlScore;
    double htmlScore;
    double allScore;
    double aveScore;

    public Grade(String name, double javaScore, double sqlScore, double htmlScore) {
        this.name = name;
        this.javaScore = javaScore;
        this.sqlScore = sqlScore;
        this.htmlScore = htmlScore;
        allScore = getAllScore();
        aveScore = getAveScore();
    }

    public Grade() {
    }

    public Grade(String str) {
        String[] a = str.split(",");

        this.name = a[0];
        this.javaScore = Double.parseDouble(a[1]);
        this.sqlScore = Double.parseDouble(a[2]);
        this.htmlScore = Double.parseDouble(a[3]);
        allScore = getAllScore();
        aveScore = getAveScore();


    }


    public Grade(String name, double javaScore, double sqlScore, double htmlScore, double allScore, double aveScore) {
        this.name = name;
        this.javaScore = javaScore;
        this.sqlScore = sqlScore;
        this.htmlScore = htmlScore;
        this.allScore = allScore;
        this.aveScore = aveScore;
    }

    double getAllScore() {
        return javaScore + sqlScore + htmlScore;
    }

    double getAveScore() {

        double ave = allScore / 3;
        ave = (int) (ave * 100.0);
        return ave / 100;
    }

    /**
     * 获取
     *
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     *
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     *
     * @return javaScore
     */
    public double getJavaScore() {
        return javaScore;
    }

    /**
     * 获取
     *
     * @return sqlScore
     */
    public double getSqlScore() {
        return sqlScore;
    }


    /**
     * 获取
     *
     * @return htmlScore
     */
    public double getHtmlScore() {
        return htmlScore;
    }


    public String toString() {
        return name + "\t" + javaScore + "\t" + sqlScore + "\t" + htmlScore + "\t" + allScore + "\t" + aveScore;
    }

    @Override
    public int compareTo(Grade o) {
        return (this.allScore > o.allScore) ? -1 : ((this.allScore == o.allScore) ? 0 : 1);
    }
}
